package azku.entitys;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import azku.MyApplication;
import azku.net.HttpHelper;
import azku.photoviews.DataSetting;
import azku.photoviews.R;

public class EItemViewChild {
	public static final String KEY_PHOTOID = "photoid";
	public static final String KEY_ITEMID = "itemid";
	public static final String KEY_IMGPATH = "imgpath";
	public static final String KEY_VINDEX = "vindex";
	public static final String KEY_VPOWER = "vpower";

	private int mPhotoID;
	private int mItemID;
	private String mImageUrl;
	private int mVindex;
	private int mVpower;

	private Bitmap mImage;

	public EItemViewChild() {
		mPhotoID = 0;
		mItemID = 0;
		mVindex = 1;
		mVpower = 0;
	}

	public void setPhotoID(int photoid) {
		this.mPhotoID = photoid;
	}

	public int getPhotoID() {
		return this.mPhotoID;
	}

	public void setItemID(int itemid) {
		this.mItemID = itemid;
	}

	public int getItemID() {
		return this.mItemID;
	}

	public void setVindex(int vindex) {
		this.mVindex = vindex;
	}

	public int getVindex() {
		return this.mVindex;
	}

	public void setVpower(int vpower) {
		this.mVpower = vpower;
	}

	public int getVpower() {
		return this.mVpower;
	}

	public void setImageUrl(String imageurl) {
		this.mImageUrl = imageurl;
	}

	public String getImageUrl() {
		return this.mImageUrl;
	}

	public Bitmap getImage() {
		if (mImage == null) {
			if (!this.getImageUrl().equals("")) {
				this.mImage = HttpHelper
						.GetBitmap((DataSetting.S_URL_WEBSITE + this
								.getImageUrl()));
			}
			if (this.mImage == null) {
				this.mImage = BitmapFactory.decodeResource(MyApplication
						.getInstance().getResources(), R.drawable.loading);
			}
		}
		return mImage;
	}

	public void bindParams(JSONObject obj) {
		if (obj == null)
			return;
		try {
			this.setPhotoID(obj.getInt(KEY_PHOTOID));
			this.setItemID(obj.getInt(KEY_ITEMID));
			this.setVindex(obj.getInt(KEY_VINDEX));
			this.setVpower(obj.getInt(KEY_VPOWER));
			this.setImageUrl(obj.getString(KEY_IMGPATH));
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}
